|||##########################################################################
|||## A Macroquest2 Casino written by Grimshad & Killians
|||## casinoroulette.mac - Handles all roulette code
|||##########################################################################
|||---------------------------------------------------------------------------------------------------------Roulette Events
#event Playroulette "#1# says, 'Play Roulette'"
#event Donebet "#1# says, 'Done'"
#event Roulette "#1# #*# 'Roulette'"
#event Positions "#1# #*# 'Positions'"
#event Returns "#1# #*# 'Returns'"
|||---------------------------------------------------------------------------------------------------------Roulette Initialization
Sub RInit
	/if (${Debug}) /echo in RInit
	/declare RState int outer 0
	||| RState 0=none 1=betting 2=playing 3=returns
	/declare RTableArray[10] string outer 0
/return

|||---------------------------------------------------------------------------------------------------------Roulette info
Sub Event_Roulette(Line, Player)
	/if (${Debug}) /echo in Roulette(${Player})
	/varset Player ${Player.Right[-2].Left[-1]}
	/delay ${TellDelay}
	/tell ${Player} In this game, you place a bet on any valid position, but [Positions] different [Returns] than 00 Roulette, 37=00. To place a bet, name the position and amount to place on it. You may place multiple bets. [Play Roulette]?
/return

Sub Event_Positions(Line, Player)
	/if (${Debug}) /echo in Positions(${Player})
	/varset Player ${Player.Right[-2].Left[-1]}
	/delay ${TellDelay}
	/tell ${Player} Valid Positions: 0, 00, 1-36, Red, Black, Even, Odd, 1/2, 2/2, 1/3, 2/3, 3/3, 1/3c, 2/3c, 3/3c, double # #, quad # # # #
/return

Sub Event_Returns(Line, Player)
	/if (${Debug}) /echo in Returns(${Player})
	/varset Player ${Player.Right[-2].Left[-1]}
	/delay ${TellDelay}
	/tell ${Player} Returns:(Red, Black, Even, Odd, 1/2, 2/2 =2x) (1/2, 2/2, 1/3, 2/3, 3/3, 1/3c, 2/3c, 3/3c, quad # # # # =3x) (double # # =4x) (0, 00, 1-36 =10x)
/return
|||---------------------------------------------------------------------------------------------------------Roulette
Sub Event_Playroulette(Line, Player)
	/if (${Debug}) /echo in Playroulette(${Player})
	/varset Player ${Player.Right[-2].Left[-1]}
	|||-------------------------------Out of Order
	/say ${Player}, I'm sorry, but Roulette is currently out of order.
	/return
	|||-------------------------------Out of Order
	/if (!${Defined[${Player}]}) {
		/call BankedCheck ${Player}
		/if (!${Macro.Return}) /return
	}
	/if (${${Player}[2]} == 3) {
		/say ${Player}, Please wait until you are removed from your current table before starting a new game.
		/return
	}
	|||Fill the table
	/declare i int local
	/for i 1 to 11
		/if (${i} == 11) {
			/say ${Player}, The roulette table is currently full, please play a different game or wait for a seat to open up.
			/return
		}
		/if (${RTableArray[${i}].Equal[0]}) {
			/varset RTableArray[${i}] ${Player}
			/goto :continueplayroulette
		}
	/next i
	
:continueplayroulette
	/call SetPlayerStatus ${Player} NONE 4 NONE
	/say ${Player} Has joined the Roulette table. Please wait for Roulette betting to open before placing your bets.
/return

Sub Event_Donebet(Line, Player)
	/if (${Debug}) /echo in Donebet(${Player})
	/varset Player ${Player.Right[-2].Left[-1]}
	|||TODO Add a bet timer with an announcement so that people can't never bet and hold the game up
	|||TODO Don't let the player use done if they have not bet anything
	|||Set done to true for this player
	/varset ${Player}[8] 1
	|||If there is still someone at the table who isn't done betting, don't start the casino roll
	/declare i int local
	/for i 1 to 10
		/if (!${RTableArray[${i}].Equal[0]}) {
			/if (${!${RTableArray[${i}]}[8]}) /return
		}
	/next i
	
	/say ${Player} has finished betting. Please wait for all bets to be placed and betting is closed. At that point the game will continue.
/return

Sub CasinoRoulette(Player, int RollMin, int RollMax, int Roll)
	/if (${Debug}) /echo in CasinoRoulette(${Player}, RollMin ${RollMin}, RollMax ${RollMax}, Roll ${Roll})
	|||Handle 00
	/if (${Roll} == 37) /varset Roll 00
	|||Handle Roll
	
	|||Handle Wins and Losses
	
	|||TODO Where am I going to store each players potential multiple bets? And HOW?
/return